package com.pronhub.luowowo.website.web.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.pronhub.luowowo.member.service.IUserInfoService;
import com.pronhub.luowowo.util.AjaxResult;
import com.pronhub.luowowo.util.Rediskey;
import com.pronhub.luowowo.website.web.util.CookieUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletResponse;

@Controller
public class UserLoginController {

    @Reference
    private IUserInfoService userInfoService;

    @RequestMapping("/userLogin")
    @ResponseBody
    public Object userLogin(HttpServletResponse response, String username, String password){

        String token = userInfoService.userLoginByusernameAndPassword(username,password);
/*
        //得到token后 把这串钥匙放到Cookie里面
        Cookie cookie = new Cookie("token",token);
        //设置共享路径 就是去哪个地方都能带上Cookie
        cookie.setPath("/");
        //最大存活时间
        cookie.setMaxAge(Rediskey.USER_LOGIN.getTime().intValue());
        response.addCookie(cookie);*/
        /**
         * 使用工具的
         */
        CookieUtil.addcookie(response,"token",token,Rediskey.USER_LOGIN.getTime().intValue());
        return AjaxResult.SUCCESS;
    }
}
